/**
 * Copyright (C), 2015-2018, XXX有限公司
 * FileName: OnLineTemperatureServiceImpl
 * Author:   周宏硕
 * Date:     2018/12/24 15:16
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.ht.temp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ht.temp.entity.OffLineTemperature;
import com.ht.temp.entity.OnLineTemperature;
import com.ht.temp.mapper.OffLineTemperatureMapper;
import com.ht.temp.mapper.OnLineTemperatureMapper;
import com.ht.temp.service.IOnLineTemperatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author 周宏硕
 * @create 2018/12/24
 * @since 1.0.0
 */
@Service
@Transactional
public class OnLineTemperatureServiceImpl extends ServiceImpl<OnLineTemperatureMapper, OnLineTemperature> implements IOnLineTemperatureService {
    @Autowired
    private  OnLineTemperatureMapper onLineTemperatureMapper;

    @Override
    public List<OnLineTemperature> getTempByMIn(Integer deviceId) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
        LocalDateTime localDateTime3 = LocalDateTime.now();
        String localTime = df.format(localDateTime3);
        return onLineTemperatureMapper.selectMinReportByMin(localTime,localTime,deviceId);
    }

    @Override
    public OnLineTemperature getAvgMin(Integer deviceId) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
        LocalDateTime localDateTime3 = LocalDateTime.now();
        String localTime = df.format(localDateTime3);
        return onLineTemperatureMapper.selectMinReportByMinAve(localTime,localTime,deviceId);
    }

    @Override
    public List<OnLineTemperature> selectByOnLineTemperature(OnLineTemperature onLineTemperature) {
        return onLineTemperatureMapper.selectByOnLineTemperature(onLineTemperature);
    }

    @Override
    public List<OnLineTemperature> getRecentlyTemperature(OnLineTemperature onLineTemperature) {
        return onLineTemperatureMapper.selectRecentlyTemperature(onLineTemperature);
    }

    @Override
    public int deleteByPrimaryKey(Integer temId) {
        return onLineTemperatureMapper.deleteByPrimaryKey(temId);
    }

    @Override
    public int insertSelectiveOnLineTemperature(OnLineTemperature record) {
        return 0;
    }

    @Override
    public OnLineTemperature selectByPrimaryKey(Integer temId) {
        return onLineTemperatureMapper.selectByPrimaryKey(temId);
    }

    @Override
    public List<OnLineTemperature> findPastrecords(Integer deviceId, String searchTime) {
        return onLineTemperatureMapper.selectPastrecords(deviceId,searchTime);
    }
}
